给整型二维数组 b[3][4]输入12个数据,计算并输出数组中所有正数之和、所有负数之和。

来源:百度知道 编辑:UC知道 时间:2024/09/28 14:22:27
C语言\C++都可

#include "stdio.h"
main()
{
int b[3][4],i,j,zh=0,fu=0;
printf("please input b[3][4]:\n");
for(i=0;i<3;i++)
for(j=0;j<4;j++)
{
scanf("%d",&b[i][j]);
if(b[i][j]>0)zh+=b[i][j];
if(b[i][j]<0)fu+=b[i][j];
}
printf("the sum of those numbers larger than 0 is : %d .\n",zh);
printf("the sum of those numbers smaller than 0 is : %d .",fu);
}

/*运行结果:
please input b[3][4]:
1 -2 3
-3 5 2
-3 -7 6
2 7 4
the sum of those numbers larger than 0 is : 30 .
the sum of those numbers smaller than 0 is : -15 .
*/

#include<cstdio>

using namespace std;

int b[3][4];

int main(){
int zheng_sum=0,fu_sum=0;
for(int i=0;i<3;++i)for(int j=0;j<4;++j){
scanf("%d",&b[i][j])
if(b[i][j]>0)zheng_sum+